$(document).ready(function(){
	setInterval('triggerWords()',1000);
	
    $('.localContentLink').click(function() {
		getLocalContent($(this));
		return false;
	});

});


function lookupDone(result) {
  
  //console.debug(result);

  if (!result.error && result.url != null) {
    addFeed(result.url);
  }
  else{
    alert('URL ERROR!');
  }
}

function showRenameTitle(category_id,sub_category_id){
	var old_title = $("#feed_title_"+category_id+'_'+sub_category_id).html();
	$("#feed_title_"+category_id+'_'+sub_category_id).html('<input type="text" id="feed_new_title_'+category_id+'_'+sub_category_id+'" value="'+old_title+'"/>');
	$("#rename_button_"+category_id+'_'+sub_category_id).html('<input type="button" value="確認" onclick="renameTitle(\''+category_id+'\',\''+sub_category_id+'\')"/><input type="button" value="取消" onclick="cancelRenameTitle(\''+category_id+'\',\''+sub_category_id+'\')"/>');
}

function showCategoryRenameTitle(category_id){
	var old_title = $("#category_title_"+category_id).html();
	$("#category_title_"+category_id).html('<input type="text" id="category_new_title_'+category_id+'" value="'+old_title+'"/>');
	$("#rename_button_"+category_id).html('<input type="button" value="確認" onclick="renameCategoryTitle(\''+category_id+'\')"/><input type="button" value="取消" onclick="cancelCategoryRenameTitle(\''+category_id+'\')"/>');
}

function cancelRenameTitle(category_id,sub_category_id){
	var old_title = $("#feed_new_title_"+category_id+"_"+sub_category_id).val();
	$("#feed_title_"+category_id+'_'+sub_category_id).html(old_title);
	$("#rename_button_"+category_id+'_'+sub_category_id).html('<input type="button" value="重新命名" onclick="showRenameTitle(\''+category_id+'\',\''+sub_category_id+'\')"/>');
}

function cancelCategoryRenameTitle(category_id){
	var old_title = $("#category_new_title_"+category_id).val();
	$("#category_title_"+category_id).html(old_title);
	$("#rename_button_"+category_id).html('<input type="button" value="重新命名" onclick="showCategoryRenameTitle(\''+category_id+'\')"/>');
}

function manageDescr(obj_id){	
	if($("#"+obj_id).css("display") == "none"){
		$("#"+obj_id).show("fast");
	}
	else{
		$("#"+obj_id).hide("slow");
	}
}

function triggerWords(){
	var scroll_top = $(window).scrollTop();
	$(".keyword_pool").each(function(){
		var pool_top = $(this).offset().top;		
		
		if(( (pool_top-scroll_top<=900) || (scroll_top>=(pool_top-400))) && $(this).css("visibility") == 'hidden'  ){				
			$(this).css("visibility","visible");				
			getWords($(this).attr("id"));		
		}
		
	});	
}

var ADs_num = new Array();
ADs_num['ads_top_1'] = 2;
ADs_num['ads_right_bottom'] = 5;
ADs_num['ads_bottom_1'] = 3;

function triggerADs(){	
	var scroll_top = $(window).scrollTop();
	$(".ads").each(function(){
		var pool_top = $(this).offset().top;			
		getADs($(this).attr("id"),ADs_num[$(this).attr("id")]);			
	});
}

function manageCategory(category){
	$(".here ul").each(function(){
		$(this).hide();
	});
	
	if($("#"+category).css("display") == "none"){
		$("#"+category).show("fast");
	}
	else{
		$("#"+category).hide("slow");
	}
	
}

